<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/css/font.css">
<link rel="stylesheet" href="/css/index.css">
<script type="text/javascript" src="/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/index.js"></script>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/layui-post.js"></script>
</head>
<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
	  <a href="">用户管理</a><a><cite>用户优惠</cite></a>
	</span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <select name="userId" id="userId" lay-search lay-verify="required"><option value="">请选择用户</option></select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach" id="search"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
<!--                    <button class="layui-btn" onclick="xadmin.open('新增','./cateringorderadd')"><i class="layui-icon layui-icon-add-circle"></i>添加</button>-->
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form" id="table" lay-filter="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="ImportExcel"></div>
</body>
<script>
$.ajaxSetup({contentType: "application/json; charset=utf-8"});
layui.use(['table','form'], function(){
	var table = layui.table
    $.post(geturl()+'/cateringUser/select?token='+sessionStorage.getItem("token"), JSON.stringify({}), function (res) {
        for(var i in res.data) $('#userId').append('<option value="'+res.data[i].userId + '">' + res.data[i].nickName + '</option>');
        layui.form.render();
    })
    $.post(geturl()+'/enums/select?token='+sessionStorage.getItem("token"), JSON.stringify({parentEnumCode:"COUPON_TYPE",orderByAscType:"enumCode"}), function (res) {
        for(var key in res.data.COUPON_TYPE) $('#sendType').append('<option value="'+key + '">' + res.data.COUPON_TYPE[key] + '</option>');
        layui.form.render();
    }).done(function(res){
        function enums(s,enumCode){
            for(var key in res.data[enumCode]) if(key === s) return res.data[enumCode][s];
        }
        table.render({
            elem: 'table', //指定元素
            url:geturl()+'/cateringUserCoupon/select?token='+sessionStorage.getItem("token"),
            contentType:'application/json',
            method:'post',
            page:true,height: $(window).height()-210,
            cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            where:{orderByType: "userId",orderByAscType: "createTime"},
            cols: [[
                //{type: 'checkbox',width: 80},
                {title: '序号',align:"center",halign:"center",width:80,type: 'numbers'},
                {field:'userName',align:"center",title:'用户账号',width:150},
                {field:'nickName',align:"center",title:'用户昵称',width:150},
                {field:'couponNo',align:"center",title:'优惠编号',width:120,},
                {field:'couponType',align:"center",title:'优惠类型',templet:function(d){ return enums(d.couponType,"COUPON_TYPE");}},
                {field:'parValue',align:"center",title:'优惠面值'},
                {field:'factValue',align:"center",title:'满减面值'},
                {field:'effectTime',align:"center",title:'生效时间'},
                {field:'failureTime',align:"center",title:'失效时间',},
                {field:'remark',align:"center",title:'使用说明',width:200,templet:function(d){ return '<div style="text-align: left;">'+d.remark+'</div>';}},
                {field:'isUse',align:"center",title:'是否使用',templet:function(d){ if(d.isUse == 0)return "否";else return "是";}},
                {field:'createTime',align:"center",title: '创建时间',width: 150,},
            ]],
        });
    })
});

$('#search').on('click', function() {
	layui.table.reload('table', {
		page: {curr: 1},
		where : {
            orderByType: "userId",
            orderByAscType: "createTime",
            userId:$("#userId").val(),
		},
	});
	return false;
});
</script>
</html>